{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 上周回顾\n",
    "## 1.字典的三种创建方式\n",
    "## 2.[字典]\n",
    "> 1.无序性\n",
    "> 2.key唯一性\n",
    "> 3.key不可变性\n",
    "\n",
    "# 本周学习内容\n",
    "## 1.字典的循环遍历\n",
    "## 2.字典的一般用法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "info = {\n",
    "    \"stu10001\":\"Alex\",\n",
    "    \"stu20002\":\"Jack\",\n",
    "    \"stu30003\":\"Marry\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu10001': 'Alex', 'stu20002': 'Jack', 'stu30003': 'Marry'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu10001\n",
      "stu20002\n",
      "stu30003\n"
     ]
    }
   ],
   "source": [
    "# i 指内容/y元素（itim）\n",
    "for i in info:\n",
    "    print(i)\n",
    "    # i只是key的值，并没有真正意义上获取到字典的完整信息"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 字典的循环 如何循环key：value 作为 items 输出\n",
    "for k,v in info.items():\n",
    "    print(k,v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "#A-2\n",
    "# 实践1： 学号的k 去掉stu 然后输出新的字典\n",
    "new_info = {}\n",
    "\n",
    "for k,v in info.items():\n",
    "    # 字典的新增\n",
    "    new_info[k[3:]] = v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'10001': 'Alex', '20002': 'Jack', '30003': 'Marry'}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
